package com.dream.base.web.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver;

import com.dream.utils.log.DreamLogUtils;
import com.dream.vo.api.StatusCode;


public class MySimpleMappingExceptionResolver extends SimpleMappingExceptionResolver {
	
	@Override
	protected void logException(Exception ex, HttpServletRequest request) {
		
		request.setAttribute("mvcerr", ex.getMessage());
		DreamLogUtils.error(this,"logException","logException", ex);
		
	}

	@Override
	public ModelAndView resolveException(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex) {
		
		if( request.getRequestURL().toString().contains("api")){
			response.setStatus(StatusCode.EX_SYS);
		}
		return super.resolveException(request, response, handler, ex);
	}
	
	
}
